﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using NCI.EasyObjects;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using CMS.BLL.Entity;
using CMS.DAL;

namespace CMS.BLL
{
    public class TourTransport
    {
        public eTourTransport   Data;

        public TourTransport()
        {
            Data = new eTourTransport();
		}

        ~TourTransport()
        {
		}

		public virtual void Dispose()
        {
		}

        public int DeleteById(int ID)
        {
            int nResult = 0;
           cTourTransport objDAL = new cTourTransport();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.MarkAsDeleted();
                objDAL.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public void LoadById(int ID)
        {
           cTourTransport objDAL = new cTourTransport();
            objDAL.LoadByPrimaryKey(ID);
            ConvertData(objDAL);
        }

        public int Insert()
        {
            int nResult = 0;
           cTourTransport objInfor = new cTourTransport(); 
            try
            {
                objInfor.AddNew();
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = objInfor.TransportID ;
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

        public int Update(int ID)
        {
            int nResult = 0;
           cTourTransport objInfor = new cTourTransport();
            try
            {
                objInfor.LoadByPrimaryKey(ID);
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = ID; 
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

        private void MappingData(cTourTransport objInfor)
        {
            objInfor.TourID = Data.TourID;
            objInfor.TransportID = Data.TransportID;
        }

        private void ConvertData(cTourTransport objInfor)
        {
            Data.TourID = objInfor.TourID;
            Data.TransportID = objInfor.TransportID;
        }
        public int DeleteByTourID(int TourID)
        {
            int nResult = 0;
            cTourTransport objInfor = new cTourTransport();
            try
            {
                nResult = objInfor.DeleteByTourID(TourID);
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }
        public DataTable Search(int TourID)
        {
            DataTable tbResult = new DataTable();
            cTourTransport objDAL = new cTourTransport();
            tbResult = objDAL.Search(TourID);
            return tbResult;
        }
    }
}
